﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Xml.Linq;

namespace GBPVRLibrary.UtilityLibrary.ComputerSystem
{
    public class SystemInformation
    {
        /// <summary>
        /// Gets the install path of GBPVR
        /// </summary>
        public static string GBPVRInstallPath
        {
            get
            {
                try
                {
                    // could use IntPtr.Size == 8 to determine if this is a 64 bit machine, but GBPVR maybe updated to be a 64bit app and use the main registry in 64bit OSs                    
                    RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Devnz");
                    if (key == null)
                        key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Devnz"); // incase they are running on a 64bit machine and gbpvr is still 32 bit
                    if (key == null)
                        return null;
                    string path = key.GetValue("GBPVR InstallDir").ToString();
                    if (path.EndsWith(@"\"))
                        path = path.Substring(0, path.Length - 1);
                    return path;
                }
                catch (Exception) { return null; }
            }
        }
        private static XDocument _GBPVRConfiguration;
        /// <summary>
        /// Gets an instance of the GBPVRConfiguration
        /// </summary>
        public static XDocument GBPVRConfiguration
        {
            get
            {
                // TODO: we need to update this if the config is changed
                if (_GBPVRConfiguration == null)
                    _GBPVRConfiguration = XDocument.Load(String.Format(@"{0}\config.xml", GBPVRInstallPath));
                return _GBPVRConfiguration;
            }
        }
    }
}
